AsgClientePoliza = function(){
	return {
		saveAbonos: function(){
			var records = Ext.getCmp("asgAbonoGrid").getStore().data.filterBy(function(item){return !item.isValid();}).items;
			if(records && records.length > 0){
				Asg.Message.alertInvalid("Se encontraron registros inv\u00E1lidos");
				return;
			}
			records = Ext.getCmp("asgAbonoGrid").getStore().data.filterBy(function(item){return item.isValid();}).items;
			var jsonString = "";
			Ext.each(records, function(record){
				jsonString += (Ext.isEmpty(jsonString) ? "" : ",") + Ext.encode(record.data);
			});
			jsonString = "[" + jsonString + "]";
			Asg.Message.progress("Guardarndo Informaci\u00F3n...");
			Ext.Ajax.request({
				timeout: Asg.constants.TIMEOUT_SECONDS,
				url: Asg.constants.CONTEXT_PATH + "/polizas/updateAbonos",
				params: {asgPolizaId: AsgSeguros.getAsgPolizaId(), jsonString: jsonString},
				callback: function(options, success, response){
					Ext.Msg.hide();
					var jsonObject = Asg.Utils.ajaxRequestGetJson(response);
					if(!success || !jsonObject){
						Asg.Message.alertInvalid(Asg.constants.DEFAULT_ERROR_MESSAGE);
						return
					}
					Asg.Message.alert(jsonObject.message || Asg.constants.DEFAULT_ERROR_MESSAGE);
					if(jsonObject.success){
						if(jsonObject.data) 
							Asg.Grid.loadData("asgAbonoGrid", jsonObject.data);
						Asg.Utils.setValue("asgPolizaCantidadCuota", jsonObject.cantidadCuotas);
						Asg.Grid.updateSelectedRow("asgPolizaGrid", "asgPoliza.asgPolizaCantidadCuota", jsonObject.cantidadCuotas);
						return;
					}
				}
			});
		},
		confirmProcess: function(asgAbonoId){
			Asg.Message.confirm(Asg.constants.CONFIRM_DELETE_MESSAGE, function(btn){
				if(btn != "no") AsgClientePoliza.processRegister(asgAbonoId);
			});
		},
		processRegister: function(asgAbonoId){
			Asg.Message.progress("Guardarndo Informaci\u00F3n...");
			Ext.Ajax.request({
				timeout: Asg.constants.TIMEOUT_SECONDS,
				url: Asg.constants.CONTEXT_PATH + "/polizas/deleteAbono",
				params: {asgPolizaId: AsgSeguros.getAsgPolizaId(), asgAbonoId: asgAbonoId},
				callback: function(options, success, response){
					Ext.Msg.hide();
					var jsonObject = Asg.Utils.ajaxRequestGetJson(response);
					if(!success || !jsonObject){
						Asg.Message.alertInvalid(Asg.constants.DEFAULT_ERROR_MESSAGE);
						return
					}
					Asg.Message.alert(jsonObject.message || Asg.constants.DEFAULT_ERROR_MESSAGE);
					if(jsonObject.success){
						if(jsonObject.data) 
							Asg.Grid.loadData("asgAbonoGrid", jsonObject.data);
						Asg.Utils.setValue("asgPolizaCantidadCuota", jsonObject.cantidadCuotas);
						Asg.Grid.updateSelectedRow("asgPolizaGrid", "asgPoliza.asgPolizaCantidadCuota", jsonObject.cantidadCuotas);
						return;
					}
				}
			});
		},
		saveCliente: function(){
			Asg.Message.progress("Guardando Informaci\u00F3n...");
			Ext.getCmp("asgClienteForm").getForm().submit({
    			url: Asg.constants.CONTEXT_PATH + "/clientes/save",
    			timeout: Asg.constants.TIMEOUT_SECONDS,
    			params: {"asgCliente.asgClienteId": AsgSeguros.getAsgClienteId()},
    			success: function(form, action){
    				Asg.Message.alert(action.result.message);
					if(action.result.success){
						AsgSeguros.setAsgClienteId(action.result.asgClienteId);
						Asg.Form.setEnable("asgClienteForm", false);
						Asg.Utils.setEnable("asgClienteEditButton", true);
						Asg.Utils.setEnable("asgPolizaGroupButtons", true);
						Asg.Utils.setEnable("asgPolizaTab", true);
						Asg.Utils.setVisible("asgClienteButton", false);
						Asg.Utils.setValue("asgPolizaNombreCliente", Asg.Utils.getValue("asgClienteNombreCompleto"));
						Asg.Utils.setDefaultValue("asgPolizaNombreCliente", Asg.Utils.getValue("asgClienteNombreCompleto"));
					}
    			},
    			failure: Asg.Form.failureProcedure
   			});
		},
		savePoliza: function(){
			Asg.Message.progress("Guardando Informaci\u00F3n...");
			Ext.getCmp("asgPolizaForm").getForm().submit({
				url: Asg.constants.CONTEXT_PATH + "/polizas/save",
				timeout: Asg.constants.TIMEOUT_SECONDS,
				params: {
					"asgPoliza.asgPolizaId": AsgSeguros.getAsgPolizaId(),
					"asgPoliza.asgCliente.asgClienteId": AsgSeguros.getAsgClienteId()
				},
				success: function(form, action){
					Asg.Message.alert(action.result.message);
					if(action.result.success){
						Asg.Form.setEnable("asgPolizaForm", false);
						Asg.Utils.setVisible("asgPolizaButton", false);
						Asg.Grid.clearSelection("asgPolizaGrid");
						if(action.result.data) 
							Asg.Grid.loadData("asgPolizaGrid", action.result.data);
						if(!Ext.isEmpty(action.result.asgPolizaId)){
							var dataIndex = Ext.getCmp("asgPolizaGrid").getStore().find("asgPoliza.asgPolizaId", action.result.asgPolizaId);
							Ext.getCmp("asgPolizaGrid").getSelectionModel().select(dataIndex);
						}
					}
				},
				failure: Asg.Form.failureProcedure
			});
		},
		confirmDeleteCliente: function(){
			if(Ext.isEmpty(AsgSeguros.getAsgClienteId())){
				Asg.Message.alertInvalid("Datos del Cliente aun no han sido guardados");
				return;
			}
			Asg.Message.confirmDelete(AsgClientePoliza.deleteCliente, null, "Se eliminara tambien la informacion asociada al cliente, tales como: " +
				"<br />* Polizas" +
				"<br />* Reclamos" +
				"<br />* Pendientes" +
				"<br />* Seguimientos" +
				"<br />* Contactos" +
				"<br />* Abonos" +
				"<br />* Pagos"
			);
		},
		deleteCliente: function(){
			Asg.Message.progress("Guardando Informaci\u00F3n...");
			Ext.Ajax.request({
    			timeout: Asg.constants.TIMEOUT_SECONDS,
  			    url: Asg.constants.CONTEXT_PATH + "/clientes/deleteCliente",
  			    params: {
  			    	asgClienteId: AsgSeguros.getAsgClienteId()
  			    },
  			    callback: function(options, success, response){
  			    	Ext.Msg.hide();
  			    	if(success){
  			    		var jsonObject = Asg.Utils.ajaxRequestGetJson(response);
  			    		if(jsonObject && jsonObject.success){
  			    			Asg.Message.confirmProcess(jsonObject.message, function(){
  			    				Asg.Message.progress("Cargando Informaci\u00F3n...");
  								document.location.href = Asg.constants.CONTEXT_PATH + "/seguros/view";
  							});
  			    		}else{
  			    			Asg.Message.alertInvalid(jsonObject ? (jsonObject.message || Asg.constants.DEFAULT_ERROR_MESSAGE) : Asg.constants.DEFAULT_ERROR_MESSAGE);
  			    		}
  			    	}
  			    }
  			});
		},
		confirmDeletePoliza: function(){
			if(!Asg.Grid.hasSelection("asgPolizaGrid")){
				Asg.Message.alertInvalid("Debe seleccionar la poliza a eliminar");
				return;
			}
			Asg.Message.confirmDelete(AsgClientePoliza.deletePoliza, null, "Se eliminara tambien la informacion asociada a la poliza, tales como: " +
				"<br />* Reclamos" +
				"<br />* Pendientes" +
				"<br />* Seguimientos" +
				"<br />* Contactos" +
				"<br />* Abonos" +
				"<br />* Pagos"
			);
		},
		deletePoliza: function(){
			Asg.Message.progress("Guardando Informaci\u00F3n...");
			Ext.Ajax.request({
    			timeout: Asg.constants.TIMEOUT_SECONDS,
  			    url: Asg.constants.CONTEXT_PATH + "/polizas/deletePoliza",
  			    params: {
  			    	asgClienteId: AsgSeguros.getAsgClienteId(),
  			    	asgPolizaId: AsgSeguros.getAsgPolizaId()
  			    },
  			    callback: function(options, success, response){
  			    	Ext.Msg.hide();
  			    	if(success){
  			    		var jsonObject = Asg.Utils.ajaxRequestGetJson(response);
  			    		if(jsonObject && jsonObject.success){
  			    			Asg.Message.alert(jsonObject.message);
  			    			Asg.Form.setEnable("asgPolizaForm", false);
  			    			Asg.Form.reset("asgPolizaForm");
  			    			Asg.Grid.loadData("asgAbonoGrid", []);
  							Asg.Utils.setVisible("asgPolizaButton", false);
  							Asg.Grid.clearSelection("asgPolizaGrid");
							Asg.Grid.loadData("asgPolizaGrid", jsonObject.data || []);
  			    		}else{
  			    			Asg.Message.alertInvalid(jsonObject ? (jsonObject.message || Asg.constants.DEFAULT_ERROR_MESSAGE) : Asg.constants.DEFAULT_ERROR_MESSAGE);
  			    		}
  			    	}
  			    }
  			});
		},
		loadData: function(){
			Asg.Message.progress("Cargando Informaci\u00F3n...");
			Ext.Ajax.request({
    			timeout: Asg.constants.TIMEOUT_SECONDS,
  			    url: Asg.constants.CONTEXT_PATH + "/polizas/findAsgAbonosByAsgPolizaId",
  			    params: {
  			    	asgPolizaId: AsgSeguros.getAsgPolizaId()
  			    },
  			    callback: function(options, success, response){
  			    	Ext.Msg.hide();
  			    	if(success){
  			    		var jsonObject = Asg.Utils.ajaxRequestGetJson(response);
  			    		if(jsonObject && jsonObject.success){
  			    			Asg.Grid.loadData("asgAbonoGrid", jsonObject.data);
  			    		}else{
  			    			Asg.Message.alertInvalid(jsonObject ? (jsonObject.message || Asg.constants.DEFAULT_ERROR_MESSAGE) : Asg.constants.DEFAULT_ERROR_MESSAGE);
  			    		}
  			    	}
  			    }
  			});
		},
		initConfig: function(config){
			Ext.define('AsgAbonoModel', {
			    extend: 'Ext.data.Model',
			    idProperty: "asgAbonoId",
			    fields: [
			          {name: "asgAbonoId", type: "int"}, 
		        	  {name: "asgAbonoNumeroCuota", type: "int"},
		        	  {name: "asgAbonoMonto", type: "string", defaultValue: "0.00"},
		        	  {
		        		  name: "asgAbonoFechaLimite",
		        		  convert: function(value){return Asg.Utils.parseDate(value, "d/m/Y", "Ymd");}
      		          },
      		          {name: "asgPolizaId", type: "int"},
      		          {name: "asgPolizaNumero", type: "string"},
      		          {name: "asgPagoId", type: "string"}
		        ],
		        validations: [
                      {type: "presence",  field: "asgAbonoFechaLimite"},
                      {type: "greaterThanZero",  field: "asgAbonoMonto"}
                ]
			});
			return {
				menu: [
			       {
	                	xtype: "buttongroup",
	                	title: "CLIENTES",
	                	defaults: {iconAlign: "left"},
	                	padding:"5 5 5 5",
	                	style: "min-width: 200px;",
			            bodyStyle:"min-height:25px",
			            hidden: config.isReadOnly && !config.allowDelete,
	                	items: [
            	        	{
            	        		text: "Crear Cliente", 
            	        		iconCls: Asg.constants.ADD_ICON,
            	        		menu: [
        	        		        {
        	        		        	text: "Persona Natural",
        	        		        	handler:Commons.createCliente
        	        		        },{
        	        		        	text: "Persona Juridica",
        	        		        	handler:Commons.createClienteJuridico
        	        		        }
    	        		        ]
        	        		},{
        	        			id: "asgClienteEditButton",
        	        			text: "Editar Cliente",
        	        			iconCls: Asg.constants.EDIT_ICON, 
        	        			handler: function(){
        	        				Asg.Form.setEnable("asgClienteForm", true);
        	        				Asg.Utils.setVisible("asgClienteButton", true);
        	        				Ext.getCmp("asgClienteForm").doLayout();
        	        				Ext.getCmp("asgClientePolizaTabpanel").setActiveTab(0);
        	        				Asg.Utils.setFocus("ctgTipoPersonaId");
        	        			}, 
        	        			disabled: config.create
    	        			},{
        	        			id: "asgClienteDeleteButton",
        	        			text: "Eliminar Cliente",
        	        			iconCls: Asg.constants.DELETE_ICON,
        	        			hidden: !config.allowDelete,
        	        			handler: AsgClientePoliza.confirmDeleteCliente,
        	        			disabled: config.create
    	        			}
	    	            ]
	                },
	                " ",
	                {
	                	xtype: "buttongroup",
	                	id: "asgPolizaGroupButtons",
	                	title: "POLIZAS",
	                	disabled: config.create,
	                	defaults: {iconAlign: "left"},
	                	padding:"5 5 5 5",
	                	style: "min-width: 200px;",
	                	bodyStyle:"min-height:25px",
	                	hidden: config.isReadOnly && !config.allowDelete,
	                	items: [
                	        {
                	        	text: "Agregar Poliza", 
                	        	iconCls: Asg.constants.ADD_ICON, 
                	        	handler: function(){
                	        		Asg.Form.setEnableAndClear("asgPolizaForm", true);
        	        				Asg.Utils.setVisible("asgPolizaButton", true);
        	        				Ext.getCmp("asgClientePolizaTabpanel").setActiveTab(1);
        	        				Ext.getCmp("asgPolizaForm").doLayout();
        	        				Asg.Grid.clearSelection("asgPolizaGrid");
        	        				Asg.Utils.setFocus("asgPolizaNumero");
        	        				Asg.Utils.setEnable("asgAbonoGrid", false);
        	        				AsgSeguros.setAsgPolizaId(null);
        	        				Asg.Grid.loadData("asgAbonoGrid", []);
                	        	}
            	        	},{
            	        		text: "Editar Poliza", 
            	        		iconCls: Asg.constants.EDIT_ICON, 
            	        		handler: function(){
            	        			Ext.getCmp("asgClientePolizaTabpanel").setActiveTab(1);
            	        			if(!Asg.Grid.hasSelection("asgPolizaGrid")){
            	        				Asg.Message.alertInvalid("Debe seleccionar una registro de poliza");
            	        				return;
            	        			}
            	        			Asg.Form.setEnable("asgPolizaForm", true);
        	        				Asg.Utils.setVisible("asgPolizaButton", true);
        	        				Ext.getCmp("asgPolizaForm").doLayout();
        	        				Asg.Utils.setEnable("asgAbonoGrid", true);
        	        				Asg.Utils.setFocus("asgPolizaNumero");
            	        		}
        	        		},{
        	        			id: "asgPolizaDeleteButton",
        	        			text: "Eliminar Poliza",
        	        			iconCls: Asg.constants.DELETE_ICON,
        	        			hidden: !config.allowDelete,
        	        			handler: AsgClientePoliza.confirmDeletePoliza,
        	        			disabled: config.create
    	        			}
            	        ]
	                },
	                "->",
	                Viewport.getMenuHome()
                ],
				items: [
			        {
			        	xtype: "tabpanel",
			        	id: "asgClientePolizaTabpanel",
			        	flex: 1,
			        	//frame: true,
			        	plain: true,
			        	minHeight: 200,
			        	deferredRender: true,
			        	activeTab: 0,
			        	listeners: {
			        		afterrender: function(){
			        			if(!config.create){
			        				Ext.getCmp("asgClienteForm").getForm().setValues(config.asgCliente);
			        				Asg.Form.setEnable("asgClienteForm", false);
			        			}else{
			        				Asg.Utils.setValue("ctgTipoPersonaId", config.asgCliente["asgCliente.ctgTipoPersona.ctgCatalogoId"]);
			        				Asg.Utils.setValue("ctgTipoPersonaNombre", config.asgCliente["asgCliente.ctgTipoPersona.ctgCatalogoNombre"]);
			        			}
			        		}
			        	},
			        	items: [
		        	        {
		        	        	xtype: "form",
		        	        	id: "asgClienteForm",
		        	        	title: "DATOS DEL CLIENTE",
		        	        	layout: "fit",
		        	        	bodyPadding: "5 5 5 5",
		        	        	tbar: {
		        	        		xtype: "toolbar",
		        	        		items: [
	        	        		        "->",
	        	        		        {
	        	        		        	id: "asgClienteButton",
	        	        		        	text: "Guardar", 
	        	        		        	hidden: !config.create,
	        	        		        	iconCls: Asg.constants.SAVE_ICON,
	        	        		        	handler: AsgClientePoliza.saveCliente
	        	        		        }
        	        		        ]
		        	        	},
		        	        	items: {
									xtype: "tabpanel",
									plain: true,
									minHeight: 200,
									deferredRender: true,
									activeTab: 0,
									items: [
					        	        {
					        	        	title: "DATOS DE LA EMPRESA EMPRESA",
					        	        	autoScroll: true,
					        	        	border: true,
					        	        	items: {
					        	        		border: false,
					        	        		height: 565,
					        	        		layout: {
						        	        		type: "table",
													columns: 6,
													tableAttrs: {
											            style: {width: "780px", "margin-top": "5px;"},
											            align: "center"
													}
						        	        	},
						        	        	defaults: Asg.Form.defaults({width: 255, colspan: 2}),
						        	        	items: [
				        	        	        	{xtype: "label", text: "Tipo de Persona:", cls: "x-form-item"},
				        	        	        	{xtype: "label", text: "Tipo Cliente:", cls: "x-form-item", colspan: 4},
				        	        	        	{
				        	        	        		xtype: "textfield",
				        	        	        		id: "ctgTipoPersonaNombre",
				        	        	        		name: "asgCliente.ctgTipoPersona.ctgCatalogoNombre",
				        	        	        		readOnly: true
			        	        	        		},{
				        	        	        		xtype: "combo",
				        	        	        		name: "asgCliente.ctgTipoCliente.ctgCatalogoId",
				        	        	        		store: new Ext.data.SimpleStore({
				        	        	        			data: config.ctgTipoClientes || [],
				        	        	        			fields: ["id", "value"]
				        	        	        		}),
				        	        	        		displayField: "value",
				        	        	        		valueField: "id",
				        	        	        		colspan: 4
			        	        	        		},
			        	        	        		{xtype: "label", text: "Raz\u00F3n Social", cls: "x-form-item", colspan: 6},
			        	        	        		{
			        	        	        			xtype: "textfield",
			        	        	        			id: "asgClientePrimerNombre",
			        	        	        			name: "asgCliente.asgClientePrimerNombre",
			        	        	        			allowBlank: false,
			        	        	        			maxLength: 200,
			        	        	        			width: 770,
			        	        	        			colspan: 6
			        	        	        		},
			        	        	        		{xtype: "label", text: "Nombre Comercial:", cls: "x-form-item", colspan: 6},
			        	        	        		{
			        	        	        			xtype: "textfield",
			        	        	        			id: "asgClienteNombreComercial",
			        	        	        			name: "asgCliente.asgClienteNombreComercial",
			        	        	        			width: 770,
			        	        	        			maxLength: 200,
			        	        	        			colspan: 6
			        	        	        		},
			        	        	        		{xtype: "label", text: "NIT:", cls: "x-form-item"},
			        	        	        		{xtype: "label", text: "No. de Registro", cls: "x-form-item"},
			        	        	        		{xtype: "label", text: "Clasificaci\u00F3n:", cls: "x-form-item"},
			        	        	        		{
			        	        	        			xtype: "textfield",
			        	        	        			id: "asgClienteDocumento2",
			        	        	        			name: "asgCliente.asgClienteDocumento2",
			        	        	        			maxLength: 14,
			        	        	        			allowBlank: false,
			        	        	        			vtype: "nit"
			        	        	        		},{
			        	        	        			xtype: "textfield",
			        	        	        			id: "asgClienteRegistro",
			        	        	        			name: "asgCliente.asgClienteRegistro",
			        	        	        			maxLength: 10
			        	        	        		},{
				        	        	        		xtype: "combo",
				        	        	        		id: "ctgClasificacionId",
				        	        	        		name: "asgCliente.ctgClasificacion.ctgCatalogoId",
				        	        	        		store: new Ext.data.SimpleStore({
				        	        	        			data: config.ctgClasificaciones || [],
				        	        	        			fields: ["id", "value"]
				        	        	        		}),
				        	        	        		displayField: "value",
				        	        	        		valueField: "id"
			        	        	        		},
			        	        	        		{xtype: "label", text: "Giro:", cls: "x-form-item", colspan: 6},
			        	        	        		{
			        	        	        			xtype: "textfield",
			        	        	        			id: "asgClienteGiro",
			        	        	        			name: "asgCliente.asgClienteGiro",
			        	        	        			maxLength: 100,
			        	        	        			colspan: 6
			        	        	        		},
			        	        	        		{xtype: "label", text: "Correo Electr\u00F3nico:", cls: "x-form-item"},
			        	        	        		{xtype: "label", text: "Correo Electr\u00F3nico Institucional:", cls: "x-form-item"},
			        	        	        		{xtype: "label", text: "Sitio WEB:", cls: "x-form-item"},
			        	        	        		{
			        	        	        			xtype: "textfield",
			        	        	        			name: "asgCliente.asgClienteCorreo",
			        	        	        			vtype: "email",
			        	        	        			maxLength: 250
			        	        	        		},{
			        	        	        			xtype: "textfield",
			        	        	        			name: "asgCliente.asgClienteCorreoTrabajo",
				        	        	        		maxLength: 250,
			        	        	        			vtype: "email"
			        	        	        		},{
			        	        	        			xtype: "textfield",
			        	        	        			name: "asgCliente.asgClienteSitioWeb",
			        	        	        			vtype: "url",
			        	        	        			maxLength: 250
			        	        	        		},
			        	        	        		{xtype: "label", text: "Nombre de la Secretaria:", cls: "x-form-item", colspan: 4, width: 515},
			        	        	        		{xtype: "label", text: "Correo Electr\u00F3nico de la Secretaria:", cls: "x-form-item"},
			        	        	        		{
			        	        	        			xtype: "textfield",
			        	        	        			name: "asgCliente.asgClienteNombreSecreteria",
				        	        	        		maxLength: 200,
			        	        	        			width: 515,
			        	        	        			colspan: 4
			        	        	        		},{
			        	        	        			xtype: "textfield",
			        	        	        			name: "asgCliente.asgClienteCorreoSecretaria",
				        	        	        		maxLength: 250,
			        	        	        			vtype: "email"
			        	        	        		},
			        	        	        		{xtype: "label", text: "Tel\u00E9fono:", cls: "x-form-item"},
			        	        	        		{xtype: "label", text: "Celular:", cls: "x-form-item"},
			        	        	        		{xtype: "label", text: "FAX:", cls: "x-form-item"},
			        	        	        		{
			        	        	        			xtype: "textfield",
			        	        	        			name: "asgCliente.asgClienteTelefono1",
			        	        	        			maxLength: 8,
			        	        	        			vtype: "telefono"
			        	        	        		},{
			        	        	        			xtype: "textfield",
			        	        	        			name: "asgCliente.asgClienteTelefono2",
			        	        	        			maxLength: 8,
			        	        	        			vtype: "telefonoCelular"
			        	        	        		},{
			        	        	        			xtype: "textfield",
			        	        	        			name: "asgCliente.asgClienteTelefono3",
			        	        	        			maxLength: 8,
			        	        	        			vtype: "telefonoDomicilio"
			        	        	        		},
			        	        	        		{xtype: "label", text: "Direcci\u00F3n:", cls: "x-form-item", colspan: 6},
			        	        	        		{
			        	        	        			xtype: "textarea",
			        	        	        			name: "asgCliente.asgClienteDireccion",
			        	        	        			maxLength: 300,
			        	        	        			width: 765,
			        	        	        			colspan: 6
			        	        	        		},
			        	        	        		{xtype: "label", text: "Departamento:", cls: "x-form-item"},
			        	        	        		{xtype: "label", text: "Municipio:", cls: "x-form-item"},
			        	        	        		{xtype: "label", text: "Colonia:", cls: "x-form-item"},
			        	        	        		{
				        	        	        		xtype: "combo",
				        	        	        		id: "ctgDepartamentoId",
				        	        	        		store: new Ext.data.SimpleStore({
				        	        	        			data: config.ctgDepartamentos || [],
				        	        	        			fields: ["id", "value"]
				        	        	        		}),
				        	        	        		displayField: "value",
				        	        	        		valueField: "id",
				        	        	        		listeners: {
				        	        	        			change: function(){
				        	        	        				var currentValue = this.getValue();
				        	        	        				if(!Ext.isEmpty(currentValue)){
				        	        	        					var data = Asg.Combo.filter(currentValue, config.ctgMunicipios, 2);
				        	        	        					Asg.Combo.loadData("ctgMunicipioId", data, false);
			        	        	        						Asg.Combo.loadData("ctgColoniaId", [], false);
				        	        	        				}else if(Ext.isEmpty(this.getValue())){
				        	        	        					Asg.Combo.removeAll("ctgMunicipioId", false);
				        	        	        					Asg.Combo.removeAll("ctgColoniaId", false);
				        	        	        				}
				        	        	        			}
				        	        	        		},
				        	        	        		allowBlank: false
			        	        	        		},{
				        	        	        		xtype: "combo",
				        	        	        		id: "ctgMunicipioId",
				        	        	        		store: new Ext.data.SimpleStore({
				        	        	        			data: [],
				        	        	        			fields: ["id", "value"]
				        	        	        		}),
				        	        	        		displayField: "value",
				        	        	        		valueField: "id",
				        	        	        		listeners: {
				        	        	        			change: function(){
				        	        	        				var currentValue = this.getValue();
				        	        	        				if(!Ext.isEmpty(currentValue)){
				        	        	        					var data = Asg.Combo.filter(currentValue, config.ctgColonias, 2);
				        	        	        					Asg.Combo.loadData("ctgColoniaId", data, false);
				        	        	        				}else if(Ext.isEmpty(this.getValue())){
				        	        	        					Asg.Combo.removeAll("ctgColoniaId", false);
				        	        	        				}
				        	        	        			}
				        	        	        		},
				        	        	        		allowBlank: false
			        	        	        		},{
				        	        	        		xtype: "combo",
				        	        	        		id: "ctgColoniaId",
				        	        	        		name: "asgCliente.ctgColonia.ctgColoniaId",
				        	        	        		store: new Ext.data.SimpleStore({
				        	        	        			data: [],
				        	        	        			fields: ["id", "value"]
				        	        	        		}),
				        	        	        		displayField: "value",
				        	        	        		valueField: "id",
				        	        	        		allowBlank: false
			        	        	        		},{
			        	        	        			xtype: "hidden",
			        	        	        			id: "ctgTipoPersonaId",
			        	        	        			name: "asgCliente.ctgTipoPersona.ctgCatalogoId"
			        	        	        		}
				        	        	        ]
					        	        	}
					        	        },{
					        	        	title: "OTROS DATOS",
					        	        	autoScroll: true,
					        	        	border: true,
					        	        	items: {
					        	        		border: false,
					        	        		height: 450,
					        	        		layout: {
						        	        		type: "table",
													columns: 6,
													tableAttrs: {
											            style: {width: "780px", "margin-top": "5px;"},
											            align: "center"
													}
						        	        	},
						        	        	defaults: Asg.Form.defaults({width: 255, colspan: 2}),
						        	        	items: [
													{xtype: "label", text: "Observaciones:", cls: "x-form-item", colspan: 6},
													{
														xtype: "textarea",
														name: "asgCliente.asgClienteObservaciones",
														maxLength: 500,
														width: 775,
														colspan: 6
													},
													{xtype: "label", text: "Seguimiento:", cls: "x-form-item", colspan: 6},
													{
														xtype: "textarea",
														name: "asgCliente.asgClienteSeguimiento",
														maxLength: 500,
														width: 775,
														colspan: 6
													}
				        	        	        ]
					        	        	}
					        	        }
									]
		        	        	}
							},{
		        	        	xtype: "form",
		        	        	title: "POLIZAS",
		        	        	id: "asgPolizaTab",
		        	        	disabled: config.create,
		        	        	layout: {
									type: "vbox",
									align : "center",
									pack  : "start"
								},
		        	        	tbar: {
		        	        		xtype: "toolbar",
		        	        		items: [
	        	        		        "->",
	        	        		        {
	        	        		        	id: "asgPolizaButton",
	        	        		        	text: "Guardar",
	        	        		        	hidden: true,
	        	        		        	iconCls: Asg.constants.SAVE_ICON,
	        	        		        	handler: AsgClientePoliza.savePoliza
	        	        		        }
        	        		        ]
		        	        	},
		        	        	items: [
	        	        	        {
				        	        	xtype: "grid",
				        	        	id: "asgPolizaGrid",
							        	margins: "5 5 5 5",
							        	height: 150,
							        	width: 900,
							        	tbar: [
						        	       "No. Poliza:", " ",
						        	       {
						        	    	   xtype: "textfield",
						        	    	   width: 250,
						        	    	   enableKeyEvents: true,
						        	    	   listeners: {
									    		   keyup: function(field, event){
									    			   if(event.keyCode == Ext.EventObject.ENTER || event.keyCode == Ext.EventObject.DOWN){
									    				   Ext.getCmp("asgPolizaGrid").getSelectionModel().select(0);
									    				   Ext.getCmp("asgPolizaGrid").getView().focus();
									    			   }else if(event.keyCode == Ext.EventObject.ESC){
									    				   Ext.getCmp("asgPolizaGrid").getStore().clearFilter();
									    				   event.stopEvent();
									    			   }else{
										    			   var store = Ext.getCmp("asgPolizaGrid").getStore();
										    			   store.clearFilter();
									    				   store.filter("asgPoliza.asgPolizaNumero", 
								    						   new RegExp("[\w|\W]*(" + this.getValue() + ")[\w|\W]*", "i"));
									    			   }
									    		   }
						        	    	   }
				        	    		   }
					        	        ],
							        	store: new Ext.data.SimpleStore({
							        		data: config.asgPolizas || [],
							        		fields: [
						        		        "asgPoliza.asgPolizaId",
						        		        "asgPoliza.asgPolizaNumero",
						        		        "asgPoliza.asgPolizaSumaAsegurada",
						        		        "asgPoliza.asgPolizaPrima",
						        		        "asgPoliza.asgPolizaCantidadCuota",
						        		        {
						        		        	name: "asgPoliza.asgPolizaFechaInicio",
						        		        	convert: function(value){return Asg.Utils.parseDate(value);}
						        		        },{
						        		        	name: "asgPoliza.asgPolizaFechaFinalizacion",
						        		        	convert: function(value){return Asg.Utils.parseDate(value);}
						        		        },
						        		        "asgPoliza.ctgAseguradora.ctgAseguradoraId",
						        		        "asgPoliza.ctgAseguradora.ctgAseguradoraNombre",
						        		        "asgPoliza.ctgTipoSeguro.ctgCatalogoId",
						        		        "asgPoliza.ctgTipoSeguro.ctgCatalogoNombre",
						        		        "asgPoliza.ctgPlan.ctgPlanId",
						        		        "asgPoliza.ctgPlan.ctgPlanNombre",
						        		        "asgPoliza.ctgAsesor.ctgAsesorId",
						        		        "asgPoliza.ctgAsesor.ctgAsesorNombreCompleto",
						        		        "asgPoliza.ctgFormaPago.ctgCatalogoId",
						        		        "asgPoliza.ctgFormaPago.ctgCatalogoNombre"
						    		        ]
							        	}),
							        	columns: [
						        	        {header: "No. Poliza", dataIndex: "asgPoliza.asgPolizaNumero", width: 110},
						        	        {header: "Aseguradora", dataIndex: "asgPoliza.ctgAseguradora.ctgAseguradoraNombre", width: 200},
						        	        {header: "Asesor", dataIndex: "asgPoliza.ctgAsesor.ctgAsesorNombreCompleto", flex: 1},
						        	        {header: "Tipo Seguro", dataIndex: "asgPoliza.ctgTipoSeguro.ctgCatalogoNombre", width: 150},
						        	        {header: "Plan", dataIndex: "asgPoliza.ctgPlan.ctgPlanNombre", width: 180}
							            ],
							            selModel: {
						        			listeners: {
						        				selectionchange: function(selectionModel, records){
						        					if(records && records.length > 0){
						        						Asg.Form.setValues("asgPolizaForm", records[0].data);
						        						Asg.Form.setEnable("asgPolizaForm", false);
						        						Asg.Utils.setVisible("asgPolizaButton", false);
						        						Asg.Utils.setEnable("asgAbonoGrid", false);
						        						AsgSeguros.setAsgPolizaId(records[0].get("asgPoliza.asgPolizaId"));
						        						AsgClientePoliza.loadData();
						        					}
						        				}
						        			}
						        		}
				        	        },{
				        	        	autoScroll: true,
				        	        	border: false,
				        	        	flex: 1,
				        	        	width: 900,
				        	        	layout: {
				        	        		type: "hbox",
											align : "center",
											pack  : "start"
				        	        	},
				        	        	items: [
			        	        	        {
					        	        		xtype: "form",
						        	        	id: "asgPolizaForm",
					        	        		border: false,
					        	        		height: 340,
					        	        		width: 450,
					        	        		layout: {
						        	        		type: "table",
													columns: 4,
													tableAttrs: {
											            style: {width: "450px", "margin-top": "5px;"},
											            align: "center"
													}
						        	        	},
						        	        	defaults: Asg.Form.defaults({width: 220, colspan: 2}),
						        	        	items: [
				        	        	        	{xtype: "label", text: "No. P\u00F3liza:", cls: "x-form-item"},
				        	        	        	{xtype: "label", text: "Fecha Incio:", cls: "x-form-item", colspan: 1, width: 105},
			        	        	        		{xtype: "label", text: "Fecha Finalizaci\u00F3n:", cls: "x-form-item", width: 105, colspan: 1},
				        	        	        	{
				        	        	        		xtype: "textfield",
				        	        	        		id: "asgPolizaNumero",
				        	        	        		name: "asgPoliza.asgPolizaNumero",
				        	        	        		allowBlank: false,
				        	        	        		disabled: true,
				        	        	        		maxLength: 20
			        	        	        		},{
			        	        	        			xtype: "datefield",
			        	        	        			name: "asgPoliza.asgPolizaFechaInicio",
			        	        	        			allowBlank: false,
			        	        	        			submitFormat: "Ymd",
			        	        	        			disabled: true,
			        	        	        			width: 100,
			        	        	        			listeners: {
			        	        	        				change: function(){
			        	        	        					if(this.getValue()){
			        	        	        						Asg.Utils.setValue("asgPolizaFechaFinalizacion", 
			        	        	        								new Date(this.getValue().setFullYear(this.getValue().getFullYear() + 1)));
			        	        	        					}
			        	        	        				}
			        	        	        			},
			        	        	        			colspan: 1
			        	        	        		},{
			        	        	        			xtype: "datefield",
			        	        	        			id: "asgPolizaFechaFinalizacion",
			        	        	        			name: "asgPoliza.asgPolizaFechaFinalizacion",
			        	        	        			allowBlank: false,
			        	        	        			submitFormat: "Ymd",
			        	        	        			disabled: true,
			        	        	        			width: 105,
			        	        	        			colspan: 1
			        	        	        		},
				        	        	        	{xtype: "label", text: "Nombre del Cliente:", cls: "x-form-item", width: 450, colspan: 4},
				        	        	        	{
			        	        	        			xtype: "textfield",
			        	        	        			id: "asgPolizaNombreCliente",
			        	        	        			value: config.asgCliente["asgCliente.asgClienteNombreCompleto"] || "",
			        	        	        			defaultValue: config.asgCliente["asgCliente.asgClienteNombreCompleto"] || "",
			        	        	        			disabled: true,
			        	        	        			allowEnable: false,
			        	        	        			width: 445,
			        	        	        			disabled: true,
			        	        	        			colspan: 4
			        	        	        		},
			        	        	        		{xtype: "label", text: "Aseguradora:", cls: "x-form-item"},
			        	        	        		{xtype: "label", text: "Tipo Seguro:", cls: "x-form-item"},
			        	        	        		{
				        	        	        		xtype: "combo",
				        	        	        		id: "ctgAseguradoraId",
				        	        	        		name: "asgPoliza.ctgAseguradora.ctgAseguradoraId",
				        	        	        		store: new Ext.data.SimpleStore({
				        	        	        			data: config.ctgAseguradoras || [],
				        	        	        			fields: ["id", "value"]
				        	        	        		}),
				        	        	        		displayField: "value",
				        	        	        		valueField: "id",
				        	        	        		listeners: {
				        	        	        			change: function(){
				        	        	        				var currentValue = this.getValue();
				        	        	        				if(!Ext.isEmpty(currentValue)){
				        	        	        					var data = Asg.Combo.filter(currentValue, config.ctgAsesores, 2);
				        	        	        					Asg.Combo.loadData("ctgAsesorId", data, false);
				        	        	        					if(!Ext.isEmpty(Asg.Utils.getValue("ctgTipoSeguro"))){
				        	        	        						data = Asg.Combo.filterByParameters([currentValue, Asg.Utils.getValue("ctgTipoSeguro")], 
				        	        	        								config.ctgPlanes, [2, 3]);
				        	        	        						Asg.Combo.loadData("ctgPlanId", data, false);
				        	        	        					}else Asg.Combo.removeAll("ctgPlanId", false);
				        	        	        				}else if(Ext.isEmpty(this.getValue())){
				        	        	        					Asg.Combo.removeAll("ctgAsesorId", false);
				        	        	        					Asg.Combo.removeAll("ctgPlanId", false);
				        	        	        				}
				        	        	        			}
				        	        	        		},
				        	        	        		disabled: true,
				        	        	        		allowBlank: false
			        	        	        		},{
				        	        	        		xtype: "combo",
				        	        	        		id: "ctgTipoSeguro",
				        	        	        		name: "asgPoliza.ctgTipoSeguro.ctgCatalogoId",
				        	        	        		store: new Ext.data.SimpleStore({
				        	        	        			data: config.ctgTipoSeguros || [],
				        	        	        			fields: ["id", "value"]
				        	        	        		}),
				        	        	        		displayField: "value",
				        	        	        		valueField: "id",
				        	        	        		listeners: {
				        	        	        			change: function(){
				        	        	        				var currentValue = this.getValue();
				        	        	        				if(!Ext.isEmpty(currentValue) && !Ext.isEmpty(Asg.Utils.getValue("ctgAseguradoraId"))){
				        	        	        					var data = Asg.Combo.filterByParameters([Asg.Utils.getValue("ctgAseguradoraId"), currentValue], 
		        	        					                         config.ctgPlanes, [2, 3]);
				        	        	        					Asg.Combo.loadData("ctgPlanId", data, false);
				        	        	        				}else if(Ext.isEmpty(this.getValue())){
				        	        	        					Asg.Combo.removeAll("ctgPlanId", false);
				        	        	        				}
				        	        	        			}
				        	        	        		},
				        	        	        		disabled: true,
				        	        	        		allowBlank: false
			        	        	        		},
			        	        	        		{xtype: "label", text: "Plan:", cls: "x-form-item"},
			        	        	        		{xtype: "label", text: "Asesor:", cls: "x-form-item"},
			        	        	        		{
				        	        	        		xtype: "combo",
				        	        	        		id: "ctgPlanId",
				        	        	        		name: "asgPoliza.ctgPlan.ctgPlanId",
				        	        	        		store: new Ext.data.SimpleStore({
				        	        	        			data: [],
				        	        	        			fields: ["id", "value"]
				        	        	        		}),
				        	        	        		displayField: "value",
				        	        	        		valueField: "id",
				        	        	        		disabled: true,
				        	        	        		allowBlank: false
			        	        	        		},{
				        	        	        		xtype: "combo",
				        	        	        		id:"ctgAsesorId",
				        	        	        		name: "asgPoliza.ctgAsesor.ctgAsesorId",
				        	        	        		store: new Ext.data.SimpleStore({
				        	        	        			data: [],
				        	        	        			fields: ["id", "value"]
				        	        	        		}),
				        	        	        		displayField: "value",
				        	        	        		valueField: "id",
				        	        	        		disabled: true,
				        	        	        		allowBlank: false
			        	        	        		},
			        	        	        		{xtype: "label", text: "Forma de Pago:", cls: "x-form-item", colspan: 4},
			        	        	        		{
				        	        	        		xtype: "combo",
				        	        	        		name: "asgPoliza.ctgFormaPago.ctgCatalogoId",
				        	        	        		store: new Ext.data.SimpleStore({
				        	        	        			data: config.ctgFormasPago || [],
				        	        	        			fields: ["id", "value"]
				        	        	        		}),
				        	        	        		displayField: "value",
				        	        	        		valueField: "id",
				        	        	        		disabled: true,
				        	        	        		colspan: 4
			        	        	        		},
			        	        	        		{xtype: "label", text: "Suma Asegurada:", cls: "x-form-item", colspan: 1, width: 105},
			        	        	        		{xtype: "label", text: "Prima Anual:", cls: "x-form-item", colspan: 1, width: 105},
			        	        	        		{xtype: "label", text: "Cuota Inicial:", cls: "x-form-item", colspan: 1, width: 105},
			        	        	        		{xtype: "label", text: "Cant. de Cuotas:", cls: "x-form-item", colspan: 1, width: 105},
			        	        	        		{
			        	        	        			xtype: "numericfield",
			        	        	        			name: "asgPoliza.asgPolizaSumaAsegurada",
			        	        	        			allowZero: false,
			        	        	        			allowBlank: false,
			        	        	        			maxLength: 20,
			        	        	        			disabled: true,
			        	        	        			width: 105,
			        	        	        			colspan: 1
			        	        	        		},{
			        	        	        			xtype: "numericfield",
			        	        	        			name: "asgPoliza.asgPolizaPrima",
			        	        	        			allowZero: false,
			        	        	        			allowBlank: false,
			        	        	        			maxLength: 10,
			        	        	        			disabled: true,
			        	        	        			width: 100,
			        	        	        			colspan: 1
			        	        	        		},{
			        	        	        			xtype: "numericfield",
			        	        	        			name: "asgPoliza.asgPolizaCuotaInicial",
			        	        	        			allowBlank: false,
			        	        	        			maxLength: 10,
			        	        	        			disabled: true,
			        	        	        			width: 100,
			        	        	        			colspan: 1
			        	        	        		},{
			        	        	        			xtype: "numberfield",
			        	        	        			id: "asgPolizaCantidadCuota",
			        	        	        			name: "asgPoliza.asgPolizaCantidadCuota",
			        	        	        			cls: "number-field",
			        	        	        			hideTrigger: true,
			        	        	        			allowDecimals: false,
			        	        	        			allowBlank: false,
			        	        	        			maxLength: 5,
			        	        	        			disabled: true,
			        	        	        			value: 12,
			        	        	        			defaultValue: 12,
			        	        	        			width: 105,
			        	        	        			colspan: 1
			        	        	        		}
				        	        	        ]
					        	        	},{
						        	        	xtype: "grid",
						        	        	title: "Detalle de Abonos a Realizar",
						        	        	id: "asgAbonoGrid",
									        	margins: "5 0 5 5",
									        	flex: 1,
									        	minHeight: 315,
									        	width: 400,
									        	disabled: true,
									        	tbar: [
								        	       "->",
								        	       {
								        	    	   text: "Agregar",
								        	    	   iconCls: Asg.constants.ADD_ICON,
								        	    	   hidden: config.isReadOnly,
								        	    	   handler: function(){
								        	    		   var grid = Ext.getCmp("asgAbonoGrid");
								        	    		   var totalCount = grid.getStore().getCount();
								        	    		   grid.getStore().insert(totalCount, AsgAbonoModel.create({asgAbonoNumeroCuota: totalCount + 1}));
								        	    		   grid.editingPlugin.startEditByPosition({row: totalCount, column: 1});
								        	    	   }
						        	    		   }, "-",
						        	    		   {
						        	    			   text: "Guardar",
						        	    			   iconCls: Asg.constants.SAVE_ICON,
						        	    			   hidden: config.isReadOnly,
						        	    			   handler: AsgClientePoliza.saveAbonos
						        	    		   }, "-",
						        	    		   {
								        	    	   text: "Refrescar",
								        	    	   iconCls: Asg.constants.REFRESH_ICON,
								        	    	   handler: function(){
								        	    		   AsgClientePoliza.loadData();
								        	    	   }
						        	    		   }
							        	        ],
									        	store: new Ext.data.Store({
									        		data: [],
									        		model: "AsgAbonoModel",
									        		proxy: {
											            type: "memory",
											            reader: {
											                type: "array"
											            }
											        },
									        		sorters: [{property: "asgAbonoNumeroCuota", direction: "ASC"}]
									        	}),
									        	selType: 'cellmodel',
									            plugins: [
									                Ext.create('Ext.grid.plugin.CellEditing', {
									                    clicksToEdit: 1
									                })
									            ],
									        	columns: [
								        	        {header: "#", dataIndex: "asgAbonoNumeroCuota", width: 30},
								        	        {
								        	        	header: "Valor de la Cuota", 
								        	        	dataIndex: "asgAbonoMonto", 
								        	        	flex: 1, 
								        	        	align: "right",
								        	        	renderer: "webMoney",
								        	        	field: {xtype: "numericfield", allowZero: false, selectOnFocus: true}
						        	        		},{
						        	        			header: "Fecha L\u00EDmite de Pago", 
						        	        			dataIndex: "asgAbonoFechaLimite", 
								        	        	width: 150, 
								        	        	align: "right",
								        	        	field: {xtype: "datefield", submitFormat: "d/m/Y", selectOnFocus: true}
						        	        		},{
								        	        	xtype:"actioncolumn",
								        	        	align: "center",
								        	        	width: 60,
							        	            	items: [
						        	            	        {
								        	            		icon: Asg.constants.CONTEXT_PATH + "/resources/images/delete.png",
								        	            		iconCls: "icon",
								        	            		tooltip: "Eliminar",
								        	            		handler: function(grid, rowIndex, colIndex) {
								        	                        var record = grid.getStore().getAt(rowIndex);
								        	                        if(record){
								        	                        	var asgAbonoId = record.get("asgAbonoId");
								        	                        	if(Ext.isEmpty(asgAbonoId) || asgAbonoId < 1){
								        	                        		grid.getStore().remove(record);
								        	                        		return;
								        	                        	}
								        	                        	if(record.get("asgPagoId") != null && record.get("asgPagoId") > 0){
								        	                        		Asg.Message.alertInvalid("Registro no puede ser eliminado, debido a que se encuentra asociado a un pago");
								        	                        		return;
								        	                        	}
								        	                        	AsgClientePoliza.confirmProcess(asgAbonoId);
								        	                        }
								        	            		}
							    	            			}
						    	            	        ]
												    }
									            ]
						        	        }
					        	        ]
				        	        }
		        	        	]
							}
	        	        ]
			        }
		        ]
			};
		}
	};
}();